home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / examples / plhold_dem < prev    next >
Text File  |  1995-05-20  |  1KB  |  68 lines

  1. #
  2. # plhold_demo.r
  3. # A simple demonstration of plhold().
  4. #
  5.  
  6. #
  7. # Start a normal plot window.
  8. #
  9.  
  10.   #  plstart(,,);
  11.  
  12. #
  13. # Set the limits cause plhold may not have enough
  14. # information to do so itself.
  15. #
  16.  
  17.   plimits (-3,3,-3,3);
  18.  
  19. #
  20. # Take care of miscelaneous items
  21. #
  22.  
  23.   pltitle ("Plhold Demo");
  24.   xlabel ("X");
  25.   ylabel ("Xdot");
  26.   plegend ("Phase-Plane Trajectory");
  27.  
  28. #
  29. # Set up for ode() usage.
  30. #
  31.  
  32.   vdpol = function ( t , x ) 
  33.   {
  34.     local(xdot);
  35.   
  36.     xdot[1;1] = x[1] * (1 - x[2]^2) - x[2];
  37.     xdot[2;1] = x[1];
  38.     return xdot;
  39.   };
  40.  
  41.  
  42.   t0 = 0; dt = 0.1; x0 = [0.3; 0.25];
  43.  
  44. #
  45. # Now go into a loop plotting the phase plane as we integrate.
  46. # This is not a very efficient way to integrate, but it is kind
  47. # of fun.
  48. #
  49.  
  50.   sout = [];
  51.   for (i in 1:200)
  52.   {
  53.     plhold ( (out = ode (vdpol, t0, tf=t0+dt, x0, dt))[;2,3] );
  54.     t0 = tf;
  55.     x0 = out[out.nr;2,3];
  56.     sout = [sout; out];
  57.   }
  58.   plptex ("STOP", out[out.nr;2], out[out.nr;3]);
  59.  
  60. #
  61. # Calling plhold_off is VERY important, plotting will
  62. # not work afterwords otherwise.
  63. #
  64.  
  65.   plhold_off ();
  66.   plegend ("default");
  67.   plimits ();
  68.